package ute.mvc.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.validation.GroupSequence;
import javax.validation.constraints.Size;
import javax.validation.groups.Default;

import org.hibernate.validator.constraints.Email;
import org.hibernate.validator.constraints.NotEmpty;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
public class User implements Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 7554525863283310548L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private int userId;

	@Column(length = 100, nullable = false, unique = true)
	private String email;

	@JsonIgnore
	@Column(length = 32, nullable = false)
	private String password;
	private boolean isActive;
	private int role = 3;
	@Column(length = 45)
	private String name;

	@JsonIgnore
	@ManyToMany(mappedBy = "listStudent")
	private Collection<MyClass> listClass = new ArrayList<MyClass>();

	@JsonIgnore
	@ManyToMany(mappedBy = "listLecturer")
	private Collection<OpenCourse> listOpenCourse = new ArrayList<OpenCourse>();

	//Vinh
	@JsonIgnore
	@OneToMany(mappedBy = "student", fetch = FetchType.LAZY)
	private Set<TestAndQuizz_Student> listSubmittedTest = new HashSet<TestAndQuizz_Student>();
	
	public Set<TestAndQuizz_Student> getListSubmittedTest() {
		return listSubmittedTest;
	}

	public void setListSubmittedTest(Set<TestAndQuizz_Student> listSubmittedTest) {
		this.listSubmittedTest = listSubmittedTest;
	}

	public Collection<MyClass> getListClass() {
		return listClass;
	}

	public void setListClass(Collection<MyClass> listClass) {
		this.listClass = listClass;
	}

	public Collection<OpenCourse> getListOpenCourse() {
		return listOpenCourse;
	}

	public void setListOpenCourse(Collection<OpenCourse> listOpenCourse) {
		this.listOpenCourse = listOpenCourse;
	}

	@NotEmpty(groups = { AddDf.class, EditDf.class })
	@Size(min = 8, max = 50, groups = { Add.class, Edit.class })
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getRole() {
		return role;
	}

	public void setRole(int role) {
		this.role = role;
	}

	public int getUserId() {
		return userId;
	}

	public void setUserId(int userId) {
		this.userId = userId;
	}

	@NotEmpty(groups = { Default.class, ResetDf.class, AddDf.class,
			EditDf.class })
	@Email(groups = { Login.class, Default.class, Reset.class, Add.class,
			AddDf.class, EditDf.class, Edit.class })
	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	@NotEmpty(groups = { Default.class, AddDf.class })
	@Size(min = 8, max = 32, groups = { Login.class, Add.class,
			ChangePass.class })
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public boolean isActive() {
		return isActive;
	}

	public void setActive(boolean isActive) {
		this.isActive = isActive;
	}

	/***********************************************************************/
	// Validate
	public interface ChangePass {

	}

	public interface ResetDf {

	}

	public interface Reset {

	}

	public interface Login {

	}

	public interface AddDf {

	}

	public interface EditDf {

	}

	public interface Add {

	}

	public interface Edit {

	}

	// Using for Edit
	@GroupSequence({ EditDf.class, Edit.class })
	public interface GroupEdit {

	}

	// Using for Add
	@GroupSequence({ AddDf.class })
	public interface GroupAdd {

	}

	// Using for Reset
	@GroupSequence({ ResetDf.class, Reset.class })
	public interface GroupReset {

	}

	// Using for Login
	@GroupSequence({ Default.class, Login.class })
	public interface GroupLogin {

	}
}
